package com.moneytalks.blazepoc.services {
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	
	/**
	 * Class provides members for handling returning propperly configured
	 * ChannelSet instances for the application.
	 **/
	public class ChannelSetManager {

		public static var DEFAULT_CAHNNEL_ID:String = "blaze-poc-amf"; 
		public static var DEFAULT_ENDPOINT_URL:String = "/messagebroker/amf"; 
		
		private var _channelId:String = DEFAULT_CAHNNEL_ID;
		public function set channelId(channel:String):void { _channelId = channel;}
		public function get channelId():String { return _channelId; }

		private var _endPointUrl:String = DEFAULT_ENDPOINT_URL;
		public function set endPointUrl(url:String):void { _endPointUrl = url;}
		public function get endPointUrl():String { return _endPointUrl; }
		
		private var _contextRootUrl:String = "";
		public function set contextRootUrl(url:String):void { _contextRootUrl = url; }
		public function get contextRootUrl():String { return _contextRootUrl; }
		
		/**
		 * Constructor for creating a new ChannelSetManager.
		 * @param urlPrefix server location
		 * @param channelId Optional override of the default channel id
		 * @param endPoint Optional endpoint URL 
		 **/
		public function ChannelSetManager(urlPrefix:String, channelId:String=null, endPoint:String=null) {
			_contextRootUrl = urlPrefix;
		}
		private function retrieveAmfEndPoint():String {
			return contextRootUrl + endPointUrl;
		}
		/**
		 * Returns a channel set with a configured AMF Channel with the
		 * current parameters in the channel set manager.
		 * @returns configured ChannelSet
		 **/
		public function retrieveChannelSet():ChannelSet {
			var cs:ChannelSet = new ChannelSet();
			var amfChannel:AMFChannel = new AMFChannel(channelId, retrieveAmfEndPoint());
			cs.addChannel(amfChannel);
			return cs;
		}
	}
}

		
